// typeof
type Person = {
    name: string;
    age: number;
};

let man: Person = {
    name: "兔兔",
    age: 18,
};

type Human = typeof man;
// type Human = {
//   name: string;
//   age: number;
// }

// --------------------------------------------
// keyof
// keyof  "name" | "age"
interface Temp {
    name: string;
    age: number;
}
type P = keyof Temp;
let p: P = "name";

// 获取value作为type
interface Eg1 {
    name: string;
    readonly age: number;
}
// string | number
type V4 = Eg1[keyof Eg1];

// --------------------------------------------
// in 操作符
type Keys = "option1" | "option2";
type Flags = { [K in Keys]: boolean };
/**
 * type Flags = {
    option1: boolean;
    option2: boolean;
*  }
 */

// --------------------------------------------
// ? 有条件类型
type TypeName<T> = T extends string
    ? "string"
    : T extends number
    ? "number"
    : T extends boolean
    ? "boolean"
    : T extends undefined
    ? "undefined"
    : T extends Function
    ? "function"
    : "object";
type T0 = TypeName<string>; // "string"
type T1 = TypeName<"a">; // "string"
type T2 = TypeName<true>; // "boolean"
type T3 = TypeName<() => void>; // "function"
type T4 = TypeName<string[]>; // "object"

// --------------------------------------------
// typeof
let str = "1234";
type slet = typeof str; // string
const strr = "1234";
type scosnt = typeof strr; // '1234'

let arr = [1, 2, 3, 4];
type alet = typeof arr; // number[]
const arrr = [1, 2, 3, 4] as const; // (as const 让每一个元素不可以被修改)
type aconst = typeof arrr; // readonly [1, 2, 3, 4]
